<template>
    <el-form ref="form" :model="singeOption" :rules="rules2" label-width="80px">
        <el-form-item label="名字" prop="name">
            <el-input v-model="singeOption.name"></el-input>
        </el-form-item>
        <el-form-item label="英文值" prop="key">
            <el-input v-model="singeOption.key"></el-input>
        </el-form-item>
        <el-form-item label="排序" :prop="'order'"
                :rules="[
                    {
                        required: true, message: '排序不能为空', trigger: 'change'
                    },
                    {
                        pattern:/^\d+$/, message: '请输入有效的排序(数值)' 
                    }
                ]">
            <el-input v-model="singeOption.order"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit('form')">修改</el-button>
            <el-button type="primary" @click="onCancel">取消</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import {computedPostSmDictionaryEidt} from "../.././css_js_img/computedSmDictionaryController"
    
    export default {
        props: [
            "singeOption"
        ],
        data(){
            return {
                rules2:{
                    name:[
                        {required:true,message:'请输入名字',trigger:'blur'}
                    ],
                    key:[
                        {required:true,message:'请输入英文值',trigger:'blur'}
                    ],
                },
            }
        },
        methods: {
            onSubmit(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        computedPostSmDictionaryEidt(this,this.singeOption)
                    } else {
                        this.$message({
                            showClose: true,
                            message: '请正确填完必要信息',
                            type: 'error'
                        });
                        return false;
                    }
                });
            },
            onCancel(){
                this.$emit('cancel',false);
            },
            refresh(){
                this.$emit("listSearch");
            }
        },
    }
</script>

